{extend name="common/base" /}
{block name="css"}
<style type="text/css">
	#wafInfo span {
		color: red;
	}

	#wafInfo .green {
		color: green;
	}

	#wafInfo .danger {
		color: red;
	}
</style>
{/block}
{block name="content"}
<div class="row">
	<div class="col-md-12">
		<div class="card load_status">
			<div class="card-header">
				<header class="card-title">
					{:__('Firewall health')}
				</header>
			</div>
			<div class="card-body">
				<div class="table-responsive">
					<table class="table table-bordered">
						<thead>
							<tr>
								<th colspan="2">{:__('Status')}：
									{if isset($Sitewaf.open)&&$Sitewaf.open}<span
										style="color:green">{:__('Open')}</span><a
										href="javascript:wafStatus('open');">[{:__('Close')}]</a>{else /}<span
										style="color:#2288cc">{:__('Close')}</span><a
										href="javascript:wafStatus('open');">[{:__('Open')}]</a>{/if}</th>
							</tr>
						</thead>
						<tbody>
							{if $total}
							<tr>
								{volist name="total" id="tal"}
								<td>{$tal.name}</td>
								{/volist}
							</tr>
							<tr>
								{volist name="total" id="tal"}
								<td>{$tal.value}</td>
								{/volist}
							</tr>
							{else /}
							<tr>
								<td>{:__('No statistics available')}</td>
							</tr>
							{/if}
						</tbody>
					</table>
				</div>



			</div>
		</div>
	</div>
</div>
<div class="row">
	<div class="col-md-12">
		<div class="card load_option">
			<div class="card-header">
				<header class="card-title">
					{:__('Waf setting')}
				</header>
			</div>
			<div class="card-body">
				<table class="table table-bordered">
					<tbody id="wafInfo">
						<tr>
							<td>{:__('Name')}</td>
							<td>{:__('Description')}</td>
							<td>{:__('Status')}</td>
							<td>{:__('Operation')}</td>
						</tr>
						<tr>
							<td>{:__('CC defense')}</td>
							<td>{:__('Within <span>%s</span> seconds, request the same URI for more than <span>%s</span> times, block IP for <span>%s</span> seconds',[$Sitewaf.cc.cycle,$Sitewaf.cc.limit,$Sitewaf.cc.endtime])}</td>
							<td>{if $Sitewaf.cc.open}<a href="javascript:wafStatus('cc')" class="green btn btn-xs btn-info"
									title="{:__('Open')}">{:__('Open')}</a>{else /}<a href="javascript:wafStatus('cc')" class="danger btn btn-xs btn-danger"
									title="{:__('Close')}">{:__('Close')}</a>{/if}</td>
							<td><a href="javascript:;" data-toggle="modal" data-target="#ccModal" class="btn btn-xs btn-warning">{:__('Setting')}</a></td>
						</tr>
						<tr>
							<td>{:__('Malicious tolerance settings')}</td>
							<td>
								{:__('In <span>%s</span> seconds, accumulate more than <span>%s</span> malicious requests, block IP for <span>%s</span> seconds',[$Sitewaf.retry_cycle,$Sitewaf.retry,$Sitewaf.retry_time])}
							</td>
							<td>--</td>
							<td><a href="javascript:;" data-toggle="modal" data-target="#retryModal" class="btn btn-xs btn-warning">{:__('Setting')}</a></td>
						</tr>
						<tr>
							<td>{:__('%sFilter','GET-URI')}</td>
							<td>{$Sitewaf.top.get.ps}</td>
							<td>{if $Sitewaf.get}<a href="javascript:wafStatus('get')" class="green btn btn-xs btn-info"
									title="{:__('Open')}">{:__('Open')}</a>{else /}<a href="javascript:wafStatus('get')" class="danger btn btn-xs btn-danger"
									title="{:__('Close')}">{:__('Close')}</a>{/if}</td>
							<td>--</td>
						</tr>
						<tr>
							<td>{:__('%sFilter','GET')}</td>
							<td>{$Sitewaf.top.get.ps}</td>
							<td>{if $Sitewaf.get}<a href="javascript:wafStatus('get')" class="green btn btn-xs btn-info"
									title="{:__('Open')}">{:__('Open')}</a>{else /}<a href="javascript:wafStatus('get')" class="danger btn btn-xs btn-danger"
									title="{:__('Close')}">{:__('Close')}</a>{/if}</td>
							<td>--</td>
						</tr>
						<tr>
							<td>{:__('%sFilter','POST')}</td>
							<td>{$Sitewaf.top.post.ps}</td>
							<td>{if $Sitewaf.post}<a href="javascript:wafStatus('post')" class="green btn btn-xs btn-info"
									title="{:__('Open')}">{:__('Open')}</a>{else /}<a href="javascript:wafStatus('post')" class="danger btn btn-xs btn-danger"
									title="{:__('Close')}">{:__('Close')}</a>{/if}</td>
							<td>--</td>
						</tr>
						<tr>
							<td>{:__('%sFilter','User-Agent')}</td>
							<td>{$Sitewaf.top['user-agent']['ps']}</td>
							<td>{if $Sitewaf['user-agent']}<a href="javascript:wafStatus('user-agent')" class="green btn btn-xs btn-info"
									title="{:__('Open')}">{:__('Open')}</a>{else /}<a href="javascript:wafStatus('user-agent')"
									class="danger btn btn-xs btn-danger" title="{:__('Close')}">{:__('Close')}</a>{/if}</td>
							<td>--</td>
						</tr>
						<tr>
							<td>{:__('%sFilter','Cookie')}</td>
							<td>{$Sitewaf.top.cookie.ps}</td>
							<td>{if $Sitewaf.cookie}<a href="javascript:wafStatus('cookie')" class="green btn btn-xs btn-info"
									title="{:__('Open')}">{:__('Open')}</a>{else /}<a href="javascript:wafStatus('cookie')" class="danger btn btn-xs btn-danger"
									title="{:__('Close')}">{:__('Close')}</a>{/if}</td>
							<td>--</td>
						</tr>
						<tr>
							<td>{:__('Overseas visits prohibited')}</td>
							<td>{$Sitewaf.top.drop_abroad.ps}</td>
							<td>{if $Sitewaf.drop_abroad}<a href="javascript:wafStatus('drop_abroad')" class="green btn btn-xs btn-info"
									title="{:__('Open')}">{:__('Open')}</a>{else /}<a href="javascript:wafStatus('drop_abroad')"
									class="danger btn btn-xs btn-danger" title="{:__('Close')}">{:__('Close')}</a>{/if}</td>
							<td>--</td>
						</tr>
						<tr>
							<td>{:__('Common scanner')}</td>
							<td>{$Sitewaf.top.scan.ps}</td>
							<td>{if $Sitewaf.scan}<a href="javascript:wafStatus('scan')" class="green btn btn-xs btn-info"
									title="{:__('Open')}">{:__('Open')}</a>{else /}<a href="javascript:wafStatus('scan')" class="danger btn btn-xs btn-danger"
									title="{:__('Close')}">{:__('Close')}</a>{/if}</td>
							<td>--</td>
						</tr>
						<tr>
							<td>{:__('Use CDN')}</td>
							<td>{:__('If this site uses CDN, and the customer IP can be obtained correctly after enabling')}</td>
							<td>{if $Sitewaf.cdn}<a href="javascript:wafStatus('cdn')" class="green btn btn-xs btn-info"
									title="{:__('Open')}">{:__('Open')}</a>{else /}<a href="javascript:wafStatus('cdn')" class="danger btn btn-xs btn-danger"
									title="{:__('Close')}">{:__('Close')}</a>{/if}</td>
							<td>--</td>
						</tr>
					</tbody>
				</table>
			</div>
		</div>
	</div>
</div>
<div class="row">
	<div class="col-md-12">
		<div class="card">
			<div class="card-header">
				<header class="card-title">
					{:__('Waf log')} <a href="javascript:$('#waflog').toggle();" class="btn btn-info btn-xs">{:__('Show/hide')}</a>
				</header>
			</div>
			<div class="card-body">
				<table class="table table-bordered">
					<tbody id="waflog" style="display: none;">
						{if $GetLog}
						<tr>
							<td>{:__('Time')}</td>
							<td>{:__('IP')}</td>
							<td>{:__('Request type')}</td>
							<td>{:__('Request path')}</td>
							<td>{:__(Referer)}</td>
							<td>{:__('Blocking rule')}</td>
							<td>{:__('Info')}</td>
						</tr>
						{volist name="GetLog" id="log"}
						<tr>
							{volist name="log" id="l"}
							<td>{$l}</td>
							{/volist}
						</tr>
						{/volist}
						{else /}
						<tr>
							<td>{:__('There is currently no interception record')}</td>
						</tr>
						{/if}
					</tbody>
				</table>
			</div>
		</div>
	</div>
</div>
<div class="modal fade" id="ccModal" tabindex="-1" role="dialog" aria-labelledby="ccModalLabel" aria-hidden="true">
	<div class="modal-dialog" role="document">
		<div class="modal-content" id="loading_box_cc">
			<div class="modal-header">
				<h6 class="modal-title" id="ccModalLabel">{:__('CC defense setting')}</h6>
				<button type="button" class="close" data-dismiss="modal" aria-label="Close">
					<span aria-hidden="true">&times;</span>
				</button>
			</div>
			<div class="modal-body">
				<div class="form-group form-inline">
					<label for="cc_mode">{:__('Mode')}：</label>
					<select name="cc_mode" id="cc_mode" class="form-control">
						<option value="1" {if @$Sitewaf.cc.cc_mode=='1' }selected='' {/if}>{:__('Noob mode')} </option>
						<option value="2" {if @$Sitewaf.cc.cc_mode=='2' }selected='' {/if}>{:__('General mode')} </option>
						{if $waf_type!='free_waf'}
						<option value="3" {if @$Sitewaf.cc.cc_mode=='3' }selected='' {/if}>{:__('Automatic mode')} </option>
						<option value="4" {if @$Sitewaf.cc.cc_mode=='4' }selected='' {/if}>{:__('Enhanced mode')} </option>
						{/if}
					</select>
				</div>
				<div class="form-group form-inline">
					<label for="cc_cycle">{:__('Cycle')}：</label>
					<input class="form-control cc_cycle" name="cc_cycle" id='cc_cycle' type="number"  value="{$Sitewaf.cc.cycle}">  <small class="text-muted"> {:__('Second')}</small>
				</div>
				<div class="form-group form-inline">
					<label for="cc_limit">{:__('Frequency')}：</label>
					<input class="form-control cc_limit" name="cc_limit" id='cc_limit' type="number"  value="{$Sitewaf.cc.limit}">  <small class="text-muted"> 次</small>
				</div>
				<div class="form-group form-inline">
					<label for="cc_endtime">{:__('Block time')}：</label>
					<input class="form-control cc_endtime" name="cc_endtime" id='cc_endtime' type="number"  value="{$Sitewaf.cc.endtime}">  <small class="text-muted"> {:__('Second')}</small>
				</div>
				<div class="form-group form-inline is_not_xb">
					<label for="increase_wu_heng">{:__('Browser auth')}：</label>
					<select name="increase_wu_heng" id="increase_wu_heng" class="form-control">
						<option value="0" {if @$Sitewaf.increase_wu_heng=='false'}selected=''{/if}>{:__('Close')} </option>
						<option value="1" {if @$Sitewaf.increase_wu_heng=='true'}selected=''{/if}>{:__('Open')} </option>
					</select>
				</div>
				<div class="form-group form-inline is_not_xb is_zq">
					<label for="cc_increase_type">{:__('Auth type')}：</label>
					<select name="cc_increase_type" id="cc_increase_type" class="form-control">
						<option value="js" {if @$Sitewaf.cc.cc_increase_type=='js'}selected=''{/if}>{:__('Jump verification')} </option>
						<option value="code" {if @$Sitewaf.cc.cc_increase_type=='code'}selected=''{/if}>{:__('Verification code verification')} </option>
					</select>
				</div>
				<div class="form-group form-inline is_not_xb">
					<label for="cc_four_defense">{:__('Four defense')}：</label>
					<select name="cc_four_defense" id="cc_four_defense" class="form-control">
						<option value="0" {if $ip_stop=='false'}selected=''{/if}>{:__('Close')}</option>
						<option value="1" {if $ip_stop=='true'}selected=''{/if}>{:__('Open')}</option>
					</select>
				</div>
				<hr>
				<small class="text-muted">
					<li>
						{:__('<span class="text-danger cc_cycle_text">%s</span> The cumulative request of the same URL exceeds <span class="text-danger cc_limit_text">%s</span> times within seconds, which triggers CC defense and blocks this IP <span class="text-danger cc_endtime_text">%s</span> seconds',[$Sitewaf.cc.cycle,$Sitewaf.cc.limit,$Sitewaf.cc.endtime])}
						<!-- <span class="text-danger cc_cycle_text">{$Sitewaf.cc.cycle}</span> 秒内累计请求同一URL超过 <span class="text-danger cc_limit_text">{$Sitewaf.cc.limit}</span> 次,触发CC防御,封锁此IP <span class="text-danger cc_endtime_text">{$Sitewaf.cc.endtime}</span> 秒 -->
					</li>
					<li>{:__('Please do not set too strict CC rules, so as not to affect the normal user experience')}</li>
					<li class="cc_borwser text-danger">{:__('Browser verification: verify whether it is a normal browser request, if the website visits abnormally after opening, please close it')}</li>
					<li class="cc_four text-danger">{:__('Enhanced mode, CC defense power enhanced version, may affect the user experience after opening.')}</li>
					<li class="cc_auto text-danger">
						{:__('When the automatic mode is set to the open state, when the website is visited <span class="cc_limit_text">600</span> times within <span class="cc_cycle_text">60</span> seconds, the enhanced mode is automatically turned on, and there is no When this rule is triggered, the enhanced mode is automatically turned off.')}
						<!-- 设置为自动模式为开启状态时，当网站 <span class="cc_cycle_text">60</span> 秒 时间内,被访问 <span class="cc_limit_text">600</span> 次自动开启增强模式，没有触发该规则，自动关闭增强模式。 -->
					</li>
				</small>
			</div>
			<div class="modal-footer">
				<button type="button" class="btn btn-secondary" data-dismiss="modal">{:__('Close')}</button>
				<button type="button" class="btn btn-warning" onclick='setWafcc("cc")'>{:__('Save')}</button>
			</div>
		</div>
	</div>
</div>
<div class="modal fade" id="retryModal" tabindex="-1" role="dialog" aria-labelledby="retryModalLabel" aria-hidden="true">
	<div class="modal-dialog" role="document">
	  <div class="modal-content" id="loading_box_retry">
		<div class="modal-header">
		  <h6 class="modal-title" id="retryModalLabel">{:__('Malicious tolerance settings')}</h6>
		  <button type="button" class="close" data-dismiss="modal" aria-label="Close">
			<span aria-hidden="true">&times;</span>
		  </button>
		</div>
		<div class="modal-body">
			<div class="form-group form-inline">
				<label for="retry_cycle">{:__('Cycle')}：</label>
				<input class="form-control retry_cycle" name="retry_cycle" id='retry_cycle' type="number" value="{$Sitewaf.retry_cycle}"> <small class="text-muted">{:__('Second')}</small>
			</div>

			<div class="form-group form-inline">
				<label for="retry">{:__('Frequency')}：</label>
				<input class="form-control retry" name="retry" id='retry' type="number" value="{$Sitewaf.retry}"> <small class="text-muted">次</small>
			</div>
		
			<div class="form-group form-inline">
				<label for="retry_time">{:__('Block time')}：</label>
				<input class="form-control retry_time" name="retry_time" id='retry_time' type="number" value="{$Sitewaf.retry_time}"> <small class="text-muted">{:__('Second')}</small>
			</div>
			<hr>
			<small class="text-muted">
				<li>
					{:__('<span class="text-danger retry_cycle_text">%s</span> accumulated malicious requests more than <span class="text-danger retry_text">%s</span> times within seconds, block <span class="text- danger retry_time_text">%s</span> seconds',[$Sitewaf.retry_cycle,$Sitewaf.retry,$Sitewaf.retry_time])}
					<!-- <span class="text-danger retry_cycle_text">{$Sitewaf.retry_cycle}</span> 秒内累计恶意请求超过  <span class="text-danger retry_text">{$Sitewaf.retry}</span> 次,封锁 <span class="text-danger retry_time_text">{$Sitewaf.retry_time}</span> {:__('Second')}</li> -->
			</small>
		</div>
		<div class="modal-footer">
		  <button type="button" class="btn btn-secondary" data-dismiss="modal">{:__('Close')}</button>
		  <button type="button" class="btn btn-warning" onclick='setWafcc("retry")'>{:__('Save')}</button>
		</div>
	  </div>
	</div>
</div>
{/block}
{block name="script"}
<script type="text/javascript">
	function it(){
		console.log($('#cc_mode').val());
		if($('#cc_mode').val()=='1'){
			$('#cc_cycle').val('60');
			$('#cc_limit').val('180');
			$('#cc_endtime').val('300');
			$('.is_not_xb').hide();
			$('.cc_auto').hide();
			$('.cc_four').hide();
			$('.cc_borwser').hide();

		}
		if($('#cc_mode').val()=='2'){
			$('#cc_cycle').val('60');
			$('#cc_limit').val('240');
			$('#cc_endtime').val('300');
			$('.is_not_xb').hide();
			$('.cc_four').hide();
			$('.cc_auto').hide();
			$('.cc_borwser').hide();
		}
		if($('#cc_mode').val()=='3'){
			$('.cc_auto').show();
			$('.is_not_xb').show();
			$('.cc_four').hide();
			$('.is_zq').hide();
			$('.cc_borwser').show();
		}
		if($('#cc_mode').val()=='4'){
			$('.is_not_xb').show();
			$('.is_zq').show();
			$('.cc_four').show();
			$('.cc_borwser').show();
		}
	}
	$(function(){
		it();
		$('#cc_mode').on('change',function(){
			it();
		});
		$('.cc_cycle,.cc_limit,.cc_endtime').on('change',function(){
			console.log($(this));
			id = $(this).attr('id');
			console.log($(this).val());
			console.log(id);
			$('.'+id+'_text').html($(this).val());
		});

		$('.retry_cycle,.retry,.retry_time').on('change',function(){
			console.log($(this));
			id = $(this).attr('id');
			console.log($(this).val());
			console.log(id);
			$('.'+id+'_text').html($(this).val());
		});
	});
	function wafStatus(type) {
		n = type=='open'?'.load_status':'.load_option';
		var l = $(n).lyearloading({
			opacity: 0.125,
			spinnerSize: 'lg'
		});
		$.post('{:url("index/vhost/wafStatus")}', {
			type: type
		}, function (res) {
			EchoMsg(res.msg, 1);
		})
		.fail(function () {
			EchoMsg('{:__("Request error, please try again later")}');
		})
		.always(function () {
			l.destroy();
		})
	}

	function setWafcc(type) {
		if (type == 'cc') {
			cycle = $('#cc_cycle').val();
			limit = $('#cc_limit').val();
			endtime = $('#cc_endtime').val();
			cc_mode = $("#cc_mode option:selected").val();
			// increase = $("#increase option:selected").val();
			increase_wu_heng = $('#increase_wu_heng option:selected').val();
			cc_increase_type = $('#cc_increase_type option:selected').val();
			cc_four_defense = $('#cc_four_defense option:selected').val();

			if (!cc_cycle || !cc_limit || !cc_endtime) {
				EchoMsg('{:__("Can not be empty")}');
				return false;
			}
			var l = $('#loading_box_cc').lyearloading({
				opacity: 0.125,
				spinnerSize: 'lg'
			});
			$.post('{:url("index/vhost/setWafcc")}', {
					type: type,
					cycle: cycle,
					limit: limit,
					endtime: endtime,
					increase_wu_heng: increase_wu_heng,
					cc_increase_type: cc_increase_type,
					cc_mode: cc_mode,
					cc_four_defense:cc_four_defense
				}, function (res) {
					EchoMsg(res.msg, 1);
				})
				.fail(function () {
					EchoMsg('{:__("Request error, please try again later")}');
				})
				.always(function () {
					l.destroy();
				})
		} else if (type == 'retry') {
			retry_cycle = $('#retry_cycle').val();
			retry = $('#retry').val();
			retry_time = $('#retry_time').val();
			if (!retry_cycle || !retry || !retry_time) {
				EchoMsg('{:__("Can not be empty")}');
				return false;
			}
			var l = $('#loading_box_retry').lyearloading({
				opacity: 0.125,
				spinnerSize: 'lg'
			});
			$.post('{:url("index/vhost/setWafcc")}', {
					type: type,
					retry_cycle: retry_cycle,
					retry: retry,
					retry_time: retry_time
				}, function (res) {
					EchoMsg(res.msg, 1);
				})
				.fail(function () {
					EchoMsg('{:__("Request error, please try again later")}');
				})
				.always(function () {
					l.destroy();
				})
		}
	}
</script>
{/block}